package publics.util;

import org.omg.CORBA.PRIVATE_MEMBER;

/**
 * 权限明细 匹配类 ， 用于匹配相应权限是否 允许相应的操作
 * @author wangshuai
 *
 */
public class LevelDetail {
	
	private String levelOneActions[] = {"index","succIn","login","logout","findPassword","riskAnalyse","welcomePage",
			"findNews","findNewsById","enterprise",
			"test","firstToCheck","secondToCheck","lastToCheck","firstCheck","secondCheck","loanOfStatuses",
			"companyExample","ratioManage","employee","admin","enterpriseType","industryType","loanType","guaranteeWay",
			
			"saveCompany","deleteCompany","updateCompany","findAllCompany","findAllCompanyName",
			"saveRatio","deleteRatio","updateRatio","findAllRatio","findAllRatioName",
			
			"saveEmployee","deleteEmployee","updateEmployee","findAllEmployee",
			"saveAdmin","deleteAdmin","updateAdmin","findAllAdmin",
			"saveEnterpriseType","deleteEnterpriseType","updateEnterpriseType","findAllEnterpriseType",
			"saveGuaranteeWay","deleteGuaranteeWay","updateGuaranteeWay","findAllGuaranteeWay",
			"saveIndustryType","deleteIndustryType","updateIndustryType","findAllIndustryType","findAllLtype",
			"saveLoanType","deleteLoanType","updateLoanType","findAllLoanType","findAllRight","findAllEthnic",
			
			"saveEnterprise","deleteEnterprise","updateEnterprise","findAllEnterprise",
			"findAllApplicationFirst","findAllApplicationSecond","findAllApplicationLast","findById","updateAppCheck"};

	//待修改！
	private String levelTwoActions[] = levelOneActions;//{"","","","","",""};
	private String levelThreeActions[] = levelOneActions;//{"","","","","",""};
	private String levelFourActions[] = levelOneActions;//{"","","","","",""};
	private String levelFiveActions[] = levelOneActions;//{"","","","","",""};
	private String levelSixActions[] = levelOneActions;//{"","","","","",""};
	private String levelSevenActions[] = levelOneActions;//{"","","","","",""};
	private String levelEightActions[] = levelOneActions;//{"","","","","",""};
	private String levelNineActions[] = levelOneActions;//{"","","","","",""};
	
	
	
	/**
	 * 匹配相应权限是否 允许相应的操作
	 * @param level   权限等级
	 * @param actionName   要访问的action的名字
	 * @return   是否有权限
	 */
	public boolean findRights(Integer level, String actionName) {
		
		if(level == null){
			System.out.println("权限为空，出错！level="+level);
			return false;
		}
		if(actionName == null || "".equals(actionName)){
			System.out.println("访问的action为空，出错！ actionName="+actionName);
			return false;
		}
		
		if(level.equals(1)){
			return  this.findAction(actionName, levelOneActions);
		}else if(level.equals(2)){
			return  this.findAction(actionName, levelTwoActions);
		}else if(level.equals(3)){
			return  this.findAction(actionName, levelThreeActions);
		}else if(level.equals(4)){
			return  this.findAction(actionName, levelFourActions);
		}else if(level.equals(5)){
			return  this.findAction(actionName, levelFiveActions);
		}else if(level.equals(6)){
			return  this.findAction(actionName, levelSixActions);
		}else if(level.equals(7)){
			System.out.println("权限等级为7， level="+level);
			return  this.findAction(actionName, levelSevenActions);
		}else if(level.equals(8)){
			return  this.findAction(actionName, levelEightActions);
		}else if(level.equals(9)){
			return  this.findAction(actionName, levelNineActions);
		}
		
		return false;
		
	}
	
	public boolean findAction(String actionName, String[] taregtActions) {
		
		for(int i = 0; i < taregtActions.length; i++){
			if(actionName.equals(taregtActions[i])){
				return true;
			}
		}
		return false;
		
	}

}
